<?php 
		// this file and function checked admin session value stored or not
		require_once("../includefiles.php");
		require_once("../model/admindetails.php");
		require_once ("../includes/classes/pagination_class.php");
		require_once '../model/contactus.php';  
		require_once '../includes/functions.php'; 
		require_once '../model/moduleuser.php';
		$Obj =  new Model_Contactus();	
		$moduleObj=new Model_ModuleUser();
		 
		 
		 /*******************************/
		if($_GET['q']=='contact')
		{
		$moduelArray=$moduleObj->getModuleHelpText(17);
		$smarty->assign('moduelArray', $moduelArray);
		}
		 if(isset($_GET['action']) == 'delete' && isset($_GET['id']) != '') {
			$id = base64_decode($_GET['id']);
			## Delete Enquiry 
			$Obj->deleteContactus($id);
			$_SESSION['msg']="<div class='success_msg'><span>Enquiry deleted successfully</span></div>";
			header('location:'.SITE_URL.'/admin/home.php?q=contact&page='.$_GET['page']);
			exit;
		}
		 
		 ## Read, Unread selected records
		/*******************************/
		if(isset($_POST['go']) != '' && isset($_POST['action']) != '') {
				$ids = implode(",", $_POST['checkall']);
				## check which action is selected
				$hidden_page = $_POST['hidden_pageno'];	
				if($_POST['action'] == 'read') {
					## Read Status selected records
					$Obj->updateContactUsStatus($ids, 'read');
					$_SESSION['msg']="<div class='success_msg'><span>Inquiry status updated successfully</span></div>";
				} else if($_POST['action'] == 'unread') {
					## Unread Status selected records
					$Obj->updateContactUsStatus($ids, 'unread');
					$_SESSION['msg']="<div class='success_msg'><span>Inquiry status updated successfully</span></div>";
				} else {
					## Delete selected records
					$Obj->deleteEnquiry($ids);
					$_SESSION['msg']="<div class='success_msg'><span>Inquiry deleted successfully</span></div>";
				}
				header('location:'.SITE_URL.'/admin/home.php?q=contact&page='.$hidden_page);
					exit;
				## Delete code will be here if required
				
		} // if close
		 
		/* Find out unread messages */
		
		##Fetch all faq pages from database
		## Get search parameters in variables - 
		if($_POST['search'] != '' && $_POST['search'] != 'Search By Name') {
		$search = addslashes($_POST['search']);
		} else if($_GET['search'] != '') {
		$search = addslashes($_GET['search']);
		} else {
		$search = '';
		}
		$smarty->assign('search', stripslashes (stripslashes ($search)));
		$contactArray= $Obj->listRecord($search);
			
	
		##  --------- Pagination part first start --------------##
		if( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != "" ) {
		 $pageNum = $_GET[ 'page' ];
		} else {
			 $pageNum = 1;
		} 
		$rowsPerPage = ROW_PER_PAGE;
		$pageName = "home.php?q=contact"; 
		## Count all the records
		$contactArray=$Obj->listRecord($search);
		$total_rows = count($contactArray);
		$offset	= ($pageNum - 1) * $rowsPerPage;
		$smarty->assign('page', $pageNum);
		##  --------- Pagination part first end --------------##
		
		##  --------- Pagination part second start --------------##
		$newid = $pageNum * $rowsPerPage - $rowsPerPage + 1;
		$smarty->assign('newid', $newid);
		$contactArray=$Obj->listRecord($search,$rowsPerPage, $offset);
		
		if($search!='' && $search!='Search')
		{
		$other_id="search=".$search;
		}
		else
		{
			$other_id="";
		}
		
		if($total_rows > ROW_PER_PAGE) {
			$pg = new pagination();					// CREATING OBJECT OF THE PAGINATION CLASS
			$pgnation = $pg->pagination_admin( $total_rows , $rowsPerPage , $pageNum , $pageName , $other_id, $class);	
			$smarty-> assign("pagination",$pgnation);
		}
		##  --------- Pagination part second end --------------##	
		
	
		$smarty->assign("contactArray",$contactArray);
		

		if($_SESSION['msg']){
			$smarty->assign("msg", $_SESSION['msg']);
			unset($_SESSION['msg']);
		}
		
//		echo '<pre>';print_r($contactArray);
		$smarty->assign('contactArray',$contactArray);


## Set active class variable for left menu  (main menu and sub menu)
$smarty->assign('activeclass', 'contact');
$smarty->assign('mainmenu', '3');

## Unset all the objects created which are on this page
unset($Obj);
unset($moduleObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'contact/contact.tpl');
unset($smarty);

?>
